package cn.wang.service.cargo.Impl;

import cn.wang.dao.BaseDao;
import cn.wang.entity.cargo.Invoice;
import cn.wang.service.cargo.InvoiceService;
import cn.wang.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by john on 2017/11/1.
 */
@Service("invoiceService")
@Transactional
public class InvoiceServiceImpl implements InvoiceService {
    @Autowired
    private BaseDao<Invoice,String>baseDao;


    @Override
    public Pagination findPage(int pageNo, int pageSize) {


        return baseDao.pageByHql("from Invoice",pageNo,pageSize);
    }

    @Override
    public List<Invoice> findAll() {
        return baseDao.getListByHQL("from Invoice");
    }

    @Override
    public void save(Invoice invoice) {
        baseDao.save(invoice);
    }

    @Override
    public void update(Invoice model) {
        baseDao.update(model);
    }

    @Override
    public Invoice findById(String id) {
        return baseDao.get(Invoice.class,id);
    }

    @Override
    public void delete(String[] ids) {
        //业务层放到service 保证在同一事务
        for (String id:ids) {
            baseDao.deleteById(Invoice.class,id);
        }
    }
}
